import 'package:flutter/material.dart';

enum AlignDemoType { topRight, origin }

class AlignDemoItem extends StatelessWidget {
  late String title;
  late Widget alignWidget;

  AlignDemoItem(AlignDemoType type, {super.key}) {
    if (type == AlignDemoType.topRight) {
      title = "Alignment.topRight";
      alignWidget = const Align(
        alignment: Alignment.topRight,
        child: FlutterLogo(
          size: 60,
        ),
      );
    }else if(type==AlignDemoType.origin){
      title = "Alignment.Origin";
      alignWidget = const Align(
        alignment: Alignment(0.5, 0.1),
        child: FlutterLogo(
          size: 60,
        ),
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(top: 10, bottom: 10),
      decoration: const BoxDecoration(color: Colors.blueAccent),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Container(
            margin: const EdgeInsets.only(right: 10),
            decoration: const BoxDecoration(color: Colors.cyan),
            child: Text(title),
          ),
          Container(
              width: 120,
              height: 120,
              color: Colors.blue[50],
              //设置背景颜色方式一
              // decoration: const BoxDecoration(color: Colors.grey), //设置背景颜色方式二
              child: alignWidget)
        ],
      ),
    );
  }
}

class AlignDemo extends StatelessWidget {
  const AlignDemo({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("AlignDemo"),
      ),
      body: Column(
        children: [
          AlignDemoItem(AlignDemoType.topRight),
          AlignDemoItem(AlignDemoType.origin),
        ],
      ),
    );
  }
}
